package com.wave2.shadow.dao;

import java.util.ArrayList;
import java.util.List;

import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Repository;

import com.wave2.shadow.persistence.Event;
import com.wave2.shadow.persistence.EventsList;

@Repository("eventsDAO")
public class EventsDAO {
	
	private static ArrayList<Event> returnList = null;		//TODO: Replace hard coded event list with a hibernate call to find events matching criteria	
	
	//TODO: Replace hard coded event list with a hibernate call to find events matching criteria
	public EventsDAO(){
				Event e1 = new Event();
				e1.setId(1);
				e1.setName("Chris-fest");
				e1.setDescription("Festival of Awesomeness!");
				e1.setOrganizer("chris");
				
				Event e2 = new Event();
				e2.setId(2);
				e2.setName("Dave-fest");
				e2.setDescription("Festival of Turd_Burgers!");
				e2.setOrganizer("dave");
				
				Event e3 = new Event();
				e3.setId(3);
				e3.setName("Ben the Stone fest");
				e3.setDescription("Festival of crappyness!");
				e3.setOrganizer("chris");
				
				returnList = new ArrayList<Event>();
				returnList.add(e1);
				returnList.add(e2);
				returnList.add(e3);
	}
	
	public EventsList getEventsByName(String organizer){
		//copy the master list over then filter then return it.
		List<Event> lst = new ArrayList<Event>();
		
		//filter list - removing matches that 
		for (int i = 0; i < returnList.size(); i++){
			Event ev = returnList.get(i);
			
			if (StringUtils.containsIgnoreCase(ev.getOrganizer(), organizer) ) {
				lst.add(ev);
			}
		}
		
		return new EventsList(lst);
	}
	
	public EventsList getDefaultList(){
		return new EventsList(returnList);
	}
	
	public EventsList deleteEvent(int eventID){
		//List<Event> lst = new ArrayList<Event>();
		//lst.addAll(returnList);
			
		//find the ID in question then remove it from the list.
		for (Event ev : returnList){
			if (ev.getId() == eventID){
				returnList.remove(ev);
				
			}
		}
		
		return new EventsList(returnList);
	}
}
